package com.example.onlinemusic.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * \* Created with IntelliJ IDEA.
 * \* User: Administrator
 * \* Date: 2022/7/26
 * \* Time: 15:27
 * \* To change this template use File | Settings | File Templates.
 * \* Description:
 * \
 */
@Configuration
public class AppConfig implements WebMvcConfigurer {
    @Bean
    public BCryptPasswordEncoder getBCryptPasswordEncoder(){
        return new BCryptPasswordEncoder();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry){
        //1、配置拦截规则
        LoginInterceptor loginInterceptor = new LoginInterceptor();
        registry.addInterceptor(loginInterceptor) .addPathPatterns("/**")
        //排除所有的JS
        .excludePathPatterns("/js/**.js")
        //排除images下所有的元素
        .excludePathPatterns("/images/**")
        .excludePathPatterns("/css/**.css")
        .excludePathPatterns("/fronts/**")
        .excludePathPatterns("/player/**")
        .excludePathPatterns("/login.html")
    //排除登录接口
        .excludePathPatterns("/user/login");
    }
}
